<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>用户充值记录</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="{{URL::asset('layui/css/layui.css')}}"  media="all">
</head>
<body>

<table class="layui-hide" id="test" lay-filter="test"></table>


<script src="{{URL::asset('layui/layui.js')}}" charset="utf-8"></script>
<script src="{{URL::asset('js/jquery-3.1.1.min.js')}}"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

<script>
    layui.use('table', function(){
        var table = layui.table;

        table.render({
            elem: '#test'
            ,url:'/admin/score/api/pay/list'
            ,toolbar: true
            ,title: '用户充值记录'
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field:'id', title:'ID', width:80, fixed: 'left', unresize: true, sort: true}
                ,{field:'order_sn', title:'订单号'}
                ,{field:'nickname', title:'用户昵称',templet:function (d) {
                        if (d.user!=null && d.user!='' && d.user!=[]) {
                            return d.user.nickname;
                        }else{
                            return '用户已删除';
                        }
                    }}
                ,{field:'money', title:'充值金额'}
                ,{field:'score', title:'获取积分'}
                ,{field:'is_paid', title:'状态',templet:function (d) {
                        if (d.is_paid==1) {
                            return '已支付';
                        }else{
                            return '未支付';
                        }
                    }}
                ,{field:'paid_at', title:'支付时间',width:200}
                ,{field:'order_status', title:'状态',templet:function (d) {
                        if (d.order_status==1) {
                            return '已付款';
                        }else{
                            return '待支付';
                        }
                    }}
                ,{field:'created_at', title:'创建时间',width:200}
            ]]
            ,page: true
        });

        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'add':
                    layer.open({
                        type:2,
                        title:"新增商品类型",
                        area:["90%","35%"],
                        content:"/admin/class/add"
                    });
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：'+ data.length + ' 个');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选': '未全选');
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event === 'del'){
                layer.confirm('该操作将永久删除数据,是否确认?', function(index){
                    $.post('/admin/score/api/delete',{"id":data.id},function (d) {
                        if (d.code==200){
                            setTimeout(function () {
                                obj.del();
                            },300)
                        }else{
                            layer.msg("删除失败");
                        }
                    });
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){
                $.post('/admin/score/api/edit',{"id":data.id},function (d) {
                    if (d.code==200){
                        setTimeout(function () {
                            obj.del();
                        },300)
                    }else{
                        layer.msg("审核失败");
                    }
                });
            }
        });
    });
</script>

</body>
</html>